package com.qdxht.dispenser.ui.activity.user;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import com.qdxht.dispenser.base.BaseActivity;
import com.qdxht.dispenser.databinding.ActivityLoginBinding;
import com.qdxht.dispenser.ui.activity.WebActivity;
import com.qdxht.dispenser.ui.activity.main.MainActivity;
import com.qdxht.dispenser.utils.SpUtils;
import com.qdxht.dispenser.view.loading.LoadingBar;

public class LoginActivity extends BaseActivity<ActivityLoginBinding> {

    @Override
    protected ActivityLoginBinding getBinding() {
        return ActivityLoginBinding.inflate(getLayoutInflater());
    }

    public static void start(Context context) {
        Intent intent = new Intent(context, LoginActivity.class);
        context.startActivity(intent);
    }

    // 0验证码 1密码
    int loginType = 0;

    @Override
    protected void initView() {
        getStatusBarConfig()
                .statusBarDarkFont(false)
                .init();
        String phone = SpUtils.get("phone");
        if(phone != null){
            binding.etLoginPhone.setText(phone);
        }
        String pwd = SpUtils.get("pwd");
        if(pwd != null){
            binding.etLoginPwd.setText(pwd);
        }

    }

    @Override
    protected void initData() {
        binding.btnLoginCommit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(loginType == 0){
                    loginYZM();
                } else {
                    loginPWD();
                }
                toHome();
            }
        });
        binding.cvLoginCountdown.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getCode();
            }
        });
        binding.tvUserAgreement.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WebActivity.start(mActivity, 0);
            }
        });
        binding.tvUserPrivate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WebActivity.start(mActivity, 1);
            }
        });

        binding.llYzm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                loginType = 0;
                binding.tvYzm.setTextColor(0xFF549AFF);
                binding.llCode.setVisibility(View.VISIBLE);

                binding.tvMm.setTextColor(0xFFFFFFFF);
                binding.etLoginPwd.setVisibility(View.GONE);
            }
        });
        binding.llMm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                loginType = 1;
                binding.tvYzm.setTextColor(0xFFFFFFFF);
                binding.llCode.setVisibility(View.GONE);
                binding.tvMm.setTextColor(0xFF549AFF);
                binding.etLoginPwd.setVisibility(View.VISIBLE);
            }
        });
    }

    public void empty(View view){
    }

    private void getCode() {

    }

    private void loginYZM() {

    }

    private void loginPWD() {

    }

    public void toHome(){
        LoadingBar.getInstance().cancel();
        MainActivity.start(mActivity);
        finish();
    }

}